#ifndef _CRITICAL_SECTION_H_
#define _CRITICAL_SECTION_H_

#include "../sleipner_config.h"

#ifdef _PLATFORM_WIN32
#include <windows.h>
#include <process.h>
namespace util 
{

class CriticalSection
{
public:
	// RAII handle
	class		Owner
	{
	public:
		Owner( CriticalSection &crit ): m_crit(crit)
		{
			m_crit.Enter();
		};
								
		~Owner()
		{
			m_crit.Leave();
		}
			
	private :
		CriticalSection &m_crit;
		Owner(const Owner &rhs);
		Owner &operator=(const Owner &rhs);
	};

	CriticalSection()
	{
		InitializeCriticalSection(&m_CS);
	};

	~CriticalSection()
	{
		DeleteCriticalSection(&m_CS);
	};

	void	Enter()
	{
		EnterCriticalSection(&m_CS); 
	};

	void	Leave()
	{
		LeaveCriticalSection(&m_CS);
	}

private:
	CRITICAL_SECTION	m_CS;
};


} // namespace util 

#endif // _PLATFORM_WIN32
#endif // _CRITICAL_SECTION_H_